#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: error_in_async.py 
@version:
@time: 2023/04/13 
"""
import asyncio

from geekPythonCore.util import async_run_time


async def worker_1():
    await asyncio.sleep(1)
    return 1


async def worker_2():
    await asyncio.sleep(2)
    return 2 / 0


async def worker_3():
    await asyncio.sleep(3)
    return 3


async def main():
    task_1 = asyncio.create_task(worker_1())
    task_2 = asyncio.create_task(worker_2())
    task_3 = asyncio.create_task(worker_3())

    await asyncio.sleep(2)

    task_3.cancel()

    res = await asyncio.gather(
        task_1,
        task_2,
        task_3,
        return_exceptions=True
    )
    print(res)


async_run_time(main)
# [1, ZeroDivisionError('division by zero'), CancelledError()]
